const { toUrl,globalData,msgLoading } = getApp()
import {request} from "@/utils/request"
Page({
    toUrl,
    data: {
        globalData,
        banner: [],
        current: 0,
        isExit: true,
        alert: false,
        sortText: '默认排序',
        sortlist: [
            {
                label: '默认排序',
                value: 0
            },
            {
                label: '开始时间升序',
                value: 1
            },
            {
                label: '开始时间倒序',
                value: 2
            },
            {
                label: '结束时间升序',
                value: 3
            },
            {
                label: '结束时间倒序',
                value: 4
            }
        ],
        headBc: '',
        act: '/img/act3.png'
    },
//处理头部滚动事件
onPageScroll(e) {
    const scrollTop = e.scrollTop
    if(scrollTop > 150 ) {
        this.setData({
            headBc: 'headbc',
            act: '/image/icon-arrow-left.png'
        })
    }else {
        this.setData({
            headBc: '',
            act: '/img/act3.png'
        })
    }
},
getbanner() {
    const data = {
        typeid: 3
    }
    request('index/bannerlist',{data}).then(res => {
        this.setData({
            banner: res.data
        })
    }).finally(()=>{
        wx.hideLoading()
    })
},
    changeSwiper ({ detail }) {
        const { current } = detail
        this.setData({ current })
    },
    back() {
        wx.navigateBack({
          delta: 1,
        })
    },
    mylisten(e) {
        this.setData({
            isExit: e.detail
        })
    },
    field(e) {
        const type = e.currentTarget.dataset.field
        const obj = this.data.sortlist.find(item => {
            return item.value == type
        })
        this.setData({
            isExit: true,
            alert: false,
            sortText: obj.label
        })
        const instance = this.selectComponent('#activelist')
        instance.setData({
            activeList: [],
            count: 1,
            page: 1,
            sort: type
        })
        instance.getList()
    },
    timeSort() {
        this.setData({
            alert: true
        })
    },
    onLoad(options) {
        msgLoading()
        const instance = this.selectComponent('#activelist')
        instance.getList()
        this.getbanner()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
        if(!this.data.isExit) {
            return
        }else {
            const instance = this.selectComponent('#activelist')
            instance.getList()
        }
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})